﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace Task启动方式
{
    class Program
    {
        static void Main(string[] args)
        {

            #region 实例化的启动方式
            Task t = new Task(() =>
            {
                Console.WriteLine($"工作线程{Thread.CurrentThread.ManagedThreadId}");
            });
            // t.RunSynchronously(); 同步方式执行
            t.Start();
            #endregion
            #region 工厂方式
            //var t = Task.Factory.StartNew(() =>
            //{
            //    Console.WriteLine($"工作线程{Thread.CurrentThread.ManagedThreadId}");
            //}); 
            #endregion

            //var t = Task.Run(() => {
            //    Console.WriteLine($"工作线程{Thread.CurrentThread.ManagedThreadId}");
            //});

            Console.Read();
        }
    }
}
